package com.example.literaturesystem.dao.user;


import com.example.literaturesystem.domain.base.BaseModel;
import com.example.literaturesystem.domain.user.User;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("userDao")
public interface IUserDao {

    @Select("<script>SELECT  * FROM usertable WHERE 1=1\n" +
            "<if test=\"userNo!=null and userNo!=''\">\n" +
            "AND UserNo=#{userNo}\n" +
            "</if>\n" +
            "<if test=\"password!=null and password!=''\">\n" +
            "AND Password=#{password}\n" +
            "</if>\n" +
            "<if test=\"userName!=null and userName!=''\">\n" +
            "AND UserName=#{userName}\n" +
            "</if>\n" +
            "<if test=\"userTeamNo!=null and userTeamNo!=''\">\n" +
            "AND UserTeamNo=#{userTeamNo}\n" +
            "</if>\n" +
            "<if test=\"iDNo!=null and iDNo!=''\">\n" +
            "AND IDNo=#{iDNo}\n" +
            "</if>\n" +
            "<if test=\"userPhone!=null and userPhone!=''\">\n" +
            " AND UserPhone=#{userPhone}\n" +
            "</if>" +
            "<if test=\"userEmail!=null and userEmail!=''\">\n" +
            "AND UserEmail=#{userEmail}\n" +
            "</if>\n" +
            "<if test=\"userRole!=null and userRole!=''\">\n" +
            "AND UserRole=#{userRole}\n" +
            "</if>\n" +
            "<if test=\"date!=null and date!=''\">\n" +
            "AND Date=#{date}\n" +
            "</if>\n" +
            "<if test=\"note!=null and note!=''\">\n" +
            "AND Note=#{note}\n" +
            "</if>\n" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            "AND DateTime=#{dateTime}\n" +
            "</if>\n" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            "AND IfUse=#{ifuse}\n" +
            "</if>\n" +
            "</script>")
    List<User> query(BaseModel baseModel);

    @Insert("<script>" +
            " INSERT INTO usertable (UserNo,Password,UserName, UserTeamNo,IDNo,UserPhone," +
            " UserEmail, UserRole, Date, Note, DateTime, IfUse,State)" +
            " VALUES (#{userNo},#{password},#{userName},#{userTeamNo},#{iDNo},#{userPhone}," +
            " #{userEmail},#{userRole},#{date},#{note},#{dateTime},#{ifuse},#{state})" +
            "</script>")
    int insert(BaseModel baseModel);

    @Update("<script>" +
            "UPDATE usertable\n" +
            " <trim prefix=\"SET\" suffixOverrides=\",\">\n" +
            "<if test=\"password!=null and password!=''\">\n" +
            " Password=#{password},\n" +
            "</if>\n" +
            "<if test=\"userName!=null and userName!=''\">\n" +
            " UserName=#{userName},\n" +
            "</if>\n" +
            "<if test=\"userTeamNo!=null and userTeamNo!=''\">\n" +
            " UserTeamNo=#{userTeamNo},\n" +
            "</if>\n" +
            "<if test=\"iDNo!=null and iDNo!=''\">\n" +
            " IDNo=#{iDNo},\n" +
            "</if>" +
            "<if test=\"userPhone!=null and userPhone!=''\">\n" +
            " UserPhone=#{userPhone},\n" +
            "</if>" +
            "<if test=\"userEmail!=null and userEmail!=''\">\n" +
            " UserEmail=#{userEmail},\n" +
            "</if>" +
            "<if test=\"userRole!=null and userRole!=''\">\n" +
            " UserRole=#{userRole},\n" +
            "</if>" +
            "<if test=\"date!=null and date!=''\">\n" +
            " Date=#{date},\n" +
            "</if>" +
            "<if test=\"note!=null and note!=''\">\n" +
            " Note=#{note},\n" +
            "</if>" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            " DateTime=#{dateTime},\n" +
            "</if>" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            " IfUse=#{ifuse}\n" +
            "</if>" +
            "<if test=\"state!=null and state!=''\">\n" +
            " State=#{state}\n" +
            "</if>" +
            " </trim>" +
            "WHERE UserNo=#{userNo}" +
            "</script>")
    int update(BaseModel baseModel);
    
    @Delete("<script>" +
    		"delete from usertable"+
    		" WHERE UserTeamNo=#{userTeamNo}"+
    		"</script>")
    int delete(BaseModel baseModel);

}
